package courseClassStatistic;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class CourseClassStatistic {
    public static void main(String[] args) throws Exception{
        Configuration conf = new Configuration();
        Job courseClassStatistic = Job.getInstance(conf);

        //指定job所在的jar包
        courseClassStatistic.setJarByClass(CourseClassStatistic.class);

        //设置job的逻辑mapper类
        courseClassStatistic.setMapperClass(mapper.class);
        //设置job的逻辑reducer类
        courseClassStatistic.setReducerClass(reducer.class);

        //设置map阶段的输出K-V数据类型
        courseClassStatistic.setMapOutputKeyClass(Text.class);
        courseClassStatistic.setMapOutputValueClass(DoubleWritable.class);

        //设置最终输出的K-V数据类型
        courseClassStatistic.setOutputKeyClass(Text.class);
        courseClassStatistic.setOutputValueClass(DoubleWritable.class);

        //设置要处理的文本数据所存放的路径
        FileInputFormat.setInputPaths(courseClassStatistic, new Path("hdfs://127.0.0.1:9000/courseClass/input"));
        FileOutputFormat.setOutputPath(courseClassStatistic, new Path("hdfs://127.0.0.1:9000/courseClass/output"));

        //提交job给集群
        courseClassStatistic.waitForCompletion(true);
    }
}
